import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { getLevelFirstJson, getLevelZeroJson, getSelectDataCommon, getTenantID } from '@/utils';

const getSearchList = (loadMdicMapList: Record<string, any>, queryTypeObj: Record<string, any>): ManageCommonAPI.ISearchList => {
  // 流程类别状态
  const categoryList = getSelectDataCommon(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}`], 'name', 'id');

  let orgDeptList: any[] = [];
  if (queryTypeObj?.params == 'createCompanyID') {
    orgDeptList = getLevelZeroJson();
  } else if (queryTypeObj?.params == 'createDepartmentID') {
    orgDeptList = getLevelFirstJson();
  }

  return [
    {
      name: 'category',
      placeholder: '业务名称',
      label: '业务名称',
      componentType: 'Select',
      dataSource: categoryList,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      treeID: 'id',
      treeName: 'name',
    },
    {
      name: 'delegateReason',
      placeholder: '委托原因',
      label: '委托原因',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'isOpen',
      placeholder: '委托状态',
      label: '委托状态',
      componentType: 'Select',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      dataSource: [
        {
          name: '有效',
          id: '1',
          value: '1',
        },
        {
          name: '禁用',
          id: '0',
          value: '0',
        },
        {
          name: '作废',
          id: '2',
          value: '2',
        },
      ],
      searchParams: {
        fieldType: 'Integer',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        isSearch: 0,
        seq: 0,
      },
    },
    {
      name: 'delegateTime',
      placeholder: '委托',
      label: '委托时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'Date',
        fieldParam: 0,
        fieldUse: 0,
        isSearch: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'assignFormName',
      placeholder: '委托',
      label: '委托',
      componentType: 'DeptAndUser',
      dataSource: orgDeptList,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
      formOrgType: {
        COMP: 'assignCompanyID',
        DEPT: 'assignDepartmentID',
        POS: 'assignPositionID',
        USER: 'assignerID',
      },
    },
    {
      name: 'agentFormName',
      placeholder: '代理',
      label: '代理',
      componentType: 'DeptAndUser',
      dataSource: orgDeptList,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
      formOrgType: {
        COMP: 'agentCompanyID',
        DEPT: 'agentDepartmentID',
        POS: 'agentPositionID',
        USER: 'agenterID',
      },
    },
    {
      name: 'remark',
      placeholder: '备注',
      label: '备注',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: true,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },

    {
      name: queryTypeObj?.params,
      placeholder: '权限参数',
      label: '权限参数',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        // fieldParam: 5,
        fieldParam:
          queryTypeObj?.params == 'createDepartmentID'
            ? 5
            : queryTypeObj?.params == 'createDepartmentID'
            ? '4'
            : queryTypeObj?.params == 'createrID'
            ? '2'
            : '3',
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
  ];
};

export { getSearchList };
